<?php
namespace App\Traits;

trait AjaxTrait
{
    public function ajaxUserLogin($request)
    {
        return [
            'phone' => $request->input('phone'),
            'pwd' => $request->input('pwd'),
        ];
    }

    public function ajaxUserLoginBySms($request)
    {
        return [
            'phone' => $request->input('phone'),
            'code' => $request->input('code'),
            'from' => $request->input('from'),
            'flag' => $request->input('flag', ''), //登录标记 1:通过统一登录入口登录，登录之后跳转到用户中心 2:满足特殊需求的登录，登录之后去填写企业基础资料
        ];
    }

    public function ajaxUserRegist($request)
    {
        return [
            'phone' => $request->input('phone'),
            'pwd' => $request->input('pwd'),
            'from' => $request->input('from', ''),
        ];
    }

    public function ajaxUserForgetPwd($request)
    {
        return [
            'account_phone' => $request->input('phone'),
            'new_pwd' => $request->input('pwd'),
        ];
    }

    public function ajaxSendSms($request)
    {
        return [
            'phone' => $request->input('phone'),
            'from' => $request->input('from'),
        ];
    }

    public function ajaxCompanyAddInfo($request)
    {
        $techPath = $request->input('tech_path');
        $newTechPath = [];
        if ($techPath) {
            foreach ($techPath as $key => $value) {
                $newTechPath[$key]['id'] = $value['id'];
                $str = '';
                $arr = array_reverse($value['key']);
                foreach ($arr as $key2 => $value2) {
                    $str = $value2 == 'true' ? ($str . '1') : $str . '0';
                }
                $newTechPath[$key]['ab'] = bindec($str);
            }
        }

        return [
            'company_name' => $request->input('company'), //单位名称
            'company_regist_address_id' => $request->input('regist_address_id'), //省市区
            'company_regist_address' => $request->input('regist_address'), //详细地址
            'company_legan_user' => $request->input('legal_person'), //法人代表
            'company_domain_id' => trim($request->input('domain'), ','), //领域
            'tech_route' => $newTechPath, //技术路径及服务能力
            'organize_regist_number_file' => $request->input('regist_number_file') != '' ? $request->input('regist_number_file') : [], //营业执照附件
            'organize_code' => $request->input('organize_code'), //组织机构代码
            'organize_code_file' => $request->input('organize_code_file') != '' ? $request->input('organize_code_file') : [], //组织机构代码附件
            'legan_user_name' => $request->input('legal_person'),
        ];
    }

}
